package com.helen.ui.donation;

import android.content.Intent;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.helen.entity.DonationListEntity;
import com.helen.shopping.R;
import com.helen.ui.BaseActivity;
import com.helen.utils.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.transformer.CubeOutTransformer;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by yang on 2018/5/4.
 * 爱心捐赠详情
 */

public class DonationDetailActivity extends BaseActivity {
    DecimalFormat df = new DecimalFormat("0.00");
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_target)
    TextView tvTarget;
    @BindView(R.id.tv_have_target)
    TextView tvHaveTarget;
    @BindView(R.id.tv_complete)
    TextView tvComplete;
    @BindView(R.id.myProgressBar)
    ProgressBar myProgressBar;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_contacts)
    TextView tvContacts;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_wx)
    TextView tvWx;
    @BindView(R.id.tv_people_num)
    TextView tvPeopleNum;
    @BindView(R.id.tv_content)
    TextView tvContent;
    private DonationListEntity donationListEntity;
    @BindView(R.id.banner)
    Banner banner;
    private List<String> bannerList = new ArrayList<>();
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_donation_detail;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText(R.string.donation_detail);
        donationListEntity = (DonationListEntity) getIntent().getSerializableExtra("donationListEntity");
        if(donationListEntity!=null){
            for (int i= 0;i<donationListEntity.getImg().size();i++){
                bannerList.add(donationListEntity.getImg().get(i).getUrl());
            }
            banner.setImages(bannerList)
                    .setImageLoader(new GlideImageLoader())
                    .setBannerAnimation(CubeOutTransformer.class)
                    .start();

            tvTitle.setText(donationListEntity.getTitle());

            int count = Integer.parseInt(new java.text.DecimalFormat("0").format(donationListEntity.getCount()));
            int haveCount = Integer.parseInt(new java.text.DecimalFormat("0").format(donationListEntity.getHavecount()));
            tvTarget.setText(count+"");
            tvHaveTarget.setText(haveCount+"");
            double speed = Double.parseDouble(df.format((double) haveCount / count));
            tvComplete.setText(" ("+speed * 100 + "%"+")");
            myProgressBar.setProgress(Integer.parseInt(new java.text.DecimalFormat("0").format(speed * 100)));
            tvType.setText(donationListEntity.getGoodstype());
            tvAddress.setText(donationListEntity.getAddress());
            tvContacts.setText(donationListEntity.getContacts());
            tvPhone.setText(donationListEntity.getPhone()+"");
            tvWx.setText(donationListEntity.getWX());
            tvPeopleNum.setText(donationListEntity.getPeoplenum()+"");
            tvContent.setText(donationListEntity.getContent()+"");

        }

    }

    @Override
    protected void updateViews() {

    }


    @OnClick(R.id.tv_donation)
    public void onViewClicked() {
        if(checkLoginState()){
            Intent ti = new Intent(DonationDetailActivity.this,UserDonationActivity.class);
            ti.putExtra("did",donationListEntity.getId());
            startActivity(ti);
        }

    }
}
